<template>
    <div class="searchPost">
        <p v-if="empty === true">没有相应数据</p>
        <Post v-for="(post,index) in list" :key="index" :post="post" :isGroup="false" v-lazy="post"/>
    </div>
</template>

<script>
import Post from './post/Post.vue'
import axios from 'axios'
export default {
    name:'SearchPost',
    components:{
        Post
    },
    data() {
        return {
            content:null,
            list:null,
            empty:false    
        }
    },
    watch:{
        '$route' (to, from) {
            if(to.query.content !== from.query.content){
                this.content = to.query.content;
                this.getInfo()
            }
        }
    },
    mounted() {
        this.content = this.$route.query.content
        this.getInfo()
    },
    methods: {
        getInfo(){
            axios({
                url:'/body/findVague',
                method:"get",
                params:{
                    message:this.content
                }
            }).then(data=>{
                console.log('搜索成功')
                this.list = data.data.data
                if(this.list.length === 0){
                    this.empty = true
                }else{
                    this.empty = false
                }
            }).catch(err=>{
                console.log(err)
            })
        }
    },
}
</script>

<style lang="less" scoped>
.searchPost{
    overflow-y: scroll;
}
</style>